<template>
<div style="backgroundColor:blue;height: 200px;width: 200px;">
  <div class="home">test1-home</div>
  <div>{{ fatherMsg }}</div>
  <button @click="handleClick">传递数据</button>
</div>
</template>

<script>
export default {
  data() {
    return {
      fatherMsg: "",
    };
  },
  mounted() {
    window.addEventListener("message", this.handleClickMessage);
  },
  methods: {
    handleClick() {
      window.parent.postMessage(
        {
          data: {
            code: "success",
            test: "我是子页面数据",
          },
        },
        "*"
      );
    },
    handleClickMessage(event) {
      if (event.data.type != "webpackOk") {
        const data = event.data.data;
        if (data.code == "success") {
          this.fatherMsg = data.test;
        }
      }
    },
  },
};
</script>

<style>

</style>